/*
 * Copyright (C) 2008
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.sca4idea.references;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.IncorrectOperationException;
import com.intellij.openapi.util.TextRange;

/**
 * Created by IntelliJ IDEA.
 * User: paul.jones
 * Date: 28-Aug-2008
 * Time: 10:27:57
 * To change this template use File | Settings | File Templates.
 */
public class XmlAttributeValuePsiReference
    implements PsiReference {
    private final TextRange range;

    public XmlAttributeValuePsiReference(XmlAttributeValue xmlAttributeValue, TextRange range)
    {
        this.xmlAttributeValue = xmlAttributeValue;
        this.range = range;
    }

    public PsiElement getElement()
    {
        return xmlAttributeValue;
    }

    public TextRange getRangeInElement()
    {
        return range;
    }

    public PsiElement resolve()
    {
        return null;
    }

    public String getTextFromRange(TextRange range) {
        return xmlAttributeValue.getValue().substring(range.getStartOffset() - 1, range.getEndOffset() - 1);
    }

    public String getCanonicalText() {
        TextRange range = getRangeInElement();

        return getTextFromRange(range);
    }

    public PsiElement handleElementRename(String newElementName)
        throws IncorrectOperationException
    {
        return null;
    }

    public PsiElement bindToElement(PsiElement element)
        throws IncorrectOperationException
    {
        return null;
    }

    public boolean isReferenceTo(PsiElement element)
    {
        return element == resolve();
    }

    public Object[] getVariants()
    {
        return new Object[0];
    }

    public boolean isSoft()
    {
        return true;
    }

    private XmlAttributeValue xmlAttributeValue;
}
